package sys.knot.util;

import org.slf4j.Logger;

import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;
import java.nio.file.Path;
import java.nio.file.Paths;

@Named
@ApplicationScoped
public class KnotPaths {

    private static final String DEFAULT_PLUGIN_DIR = "/etc/knot/plugins/";
    private static final String DEFAULT_SERVICE_DIR = "/etc/knot/services/";
    private Path pluginDir;
    private Path serviceDir;

    @Inject
    private Logger logger;

    @PostConstruct
    public void load() {
        String plugin = System.getProperty("knot.plugins.dir", DEFAULT_PLUGIN_DIR);
        String service = System.getProperty("knot.services.dir", DEFAULT_SERVICE_DIR);
        pluginDir = Paths.get(plugin);
        serviceDir = Paths.get(service);
        logger.info("Services dir: " + serviceDir.toAbsolutePath());
        logger.info("Plugins dir: " + pluginDir.toAbsolutePath());
    }

    public Path getPluginDir() {
        return pluginDir;
    }

    public Path getServiceDir() {
        return serviceDir;
    }
}
